﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="show.aspx.cs" Inherits="WebApplication1.DDD.Views.Default.users.show" %>
<%@ Register Src="~/DDD/Views/Default/Common/Public/Navigator.ascx" TagPrefix="uc1" TagName="Navigator" %>
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
    <script src="/Scripts/jquery-1.11.2.min.js"></script>
    <script src="/Scripts/Url.js"></script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table>
            <foreach enumerator="<%var u = ViewBag.us.GetEnumerator(); %>">
                <tr>
                    <td>
                        <input id="id_<%=u.Current.id %>" type="text" value="<%=u.Current.id %>" readonly="readonly" />
                    </td>
                    <td>
                        <input id="name_<%=u.Current.id %>" type="text" value="<%=u.Current.name %>" />
                    </td>
                    <td>
                        <input id="pwd_<%=u.Current.id %>" type="text" value="<%=u.Current.pwd %>" />
                    </td>
                    <td>
                        <button onclick="save(<%=u.Current.id %>);" type="button">save</button>
                        <button onclick="del(<%=u.Current.id %>);" type="button">delete</button>
                    </td>
                </tr>
            </foreach>
        </table>
        <uc1:Navigator runat="server" id="Navigator" db="<%#ViewBag.pg %>" /><br />
        插入
        <input id="name" type="text" value="" />
        <input id="pwd" type="text" value="" />
        <input type="button" onclick="insert();" value="insert" />
    </div>
    </form>
</body>
</html>
<script>
    function del(id)
    {
        $.post(Url.DDD_users_delete(id), {}, function (data) {
            if (data) {
                alert("删除成功");
            }
            else {
                alert("删除失败");
            }
        });
    }
    function insert()
    {
        var id = $("#id").val();
        var name = $("#name").val();
        var pwd = $("#pwd").val();
        $.post(Url.DDD_users_insert(id, name, pwd), {}, function (data) {
            if (data) {
                alert("添加成功");
            }
            else {
                alert("添加失败");
            }
        });
    }
    function save(ext)
    {
        var id = $("#id_" + ext).val();
        var name = $("#name_" + ext).val();
        var pwd = $("#pwd_" + ext).val();
        $.post(Url.DDD_users_edit(id, name, pwd), {}, function (data) {
            if (data) {
                alert("保存成功");
            }
            else {
                alert("保存失败");
            }
        });
    }
</script>
